import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class ListCustomHeader extends StatelessWidget {

  const ListCustomHeader({super.key});

  @override
  Widget build(BuildContext context) {
     return CustomHeader(
      builder: (BuildContext context, RefreshStatus? status) {
        Widget content;
        if (status == RefreshStatus.idle) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(CupertinoIcons.arrow_down, size: 12, color: Color.fromARGB(255, 224, 224, 224)),
            ],
          );
        } else if (status == RefreshStatus.canRefresh) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CupertinoActivityIndicator(radius: 10.0, color: Colors.blue),
            ],
          );
        } else if (status == RefreshStatus.refreshing) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CupertinoActivityIndicator(radius: 10.0, color: Colors.blue),
            ],
          );
        } else if (status == RefreshStatus.completed) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(CupertinoIcons.arrow_up, size: 14, color: Colors.green),
            ],
          );
        } else {
          content = const SizedBox.shrink();
        }
        return SizedBox(
          height: 60.0,
          child: Center(child: content),
        );
      },
    );
  }
}

class ListCustomFooter extends StatelessWidget {
  const ListCustomFooter({super.key});

  @override
  Widget build(BuildContext context) {
    return CustomFooter(
      builder: (BuildContext context, LoadStatus? status) {
        Widget content;
        if (status == LoadStatus.idle) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(CupertinoIcons.arrow_up, size: 14, color: Colors.grey),
            ],
          );
        } else if (status == LoadStatus.loading) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CupertinoActivityIndicator(radius: 10.0, color: Colors.blue),
            ],
          );
        } else if (status == LoadStatus.failed) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(Icons.error, size: 20, color: Colors.red),
              SizedBox(width: 8),
              Text("加载失败", style: TextStyle(color: Colors.red)),
            ],
          );
        } else if (status == LoadStatus.canLoading) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CupertinoActivityIndicator(radius: 10.0, color: Colors.blue),

            ],
          );
        } else if (status == LoadStatus.noMore) {
          content = const Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(Icons.info_outline, size: 20, color: Colors.grey),
              SizedBox(width: 8),
              Text("没有更多", style: TextStyle(color: Colors.grey)),
            ],
          );
        } else {
          content = const SizedBox.shrink();
        }
        return SizedBox(
          height: 60.0,
          child: Center(child: content),
        );
      },
    );
  }
}